<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.iconUrl">
          </div>
          <p class="icon-desc">
            {{item.desc}}
          </p>
        </div>
      </swiper-slide>
      
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  data () {
    return {
      swiperOption: {
        // 指定哪一个元素容器 作为页面指示页
        pagination: '.swiper-pagination',
        // 让页面原点 有切换页面的功能
        paginationClickable: true
      },
      iconLists: [
        {
          id: '100001',
          iconUrl: '//fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '美食'
        },
        {
          id: '100002',
          iconUrl: '//fuss10.elemecdn.com/c/7e/76a23eb90dada42528bc41499d6f8jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '商超便利'
        },
        {
          id: '100003',
          iconUrl: '//fuss10.elemecdn.com/0/d0/dd7c960f08cdc756b1d3ad54978fdjpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '果蔬生鲜'
        },
        {
          id: '100004',
          iconUrl: '//fuss10.elemecdn.com/7/a9/77ff360f7d3fde2d459727ad09fcfjpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '下午茶'
        },
        {
          id: '100005',
          iconUrl: '//fuss10.elemecdn.com/e/8a/1a58f9145075322665b12552da1aejpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '新品特惠'
        },
        {
          id: '100006',
          iconUrl: '//fuss10.elemecdn.com/7/0a/af108e256ebc9f02db599592ae655jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '医药健康'
        },
        {
          id: '100007',
          iconUrl: '//fuss10.elemecdn.com/a/7b/b02bd836411c016935d258b300cfejpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '大牌五折'
        },
        {
          id: '100008',
          iconUrl: '//fuss10.elemecdn.com/3/01/c888acb2c8ba9e0c813f36ec9e90ajpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '浪漫鲜花'
        },
        {
          id: '100009',
          iconUrl: '//fuss10.elemecdn.com/e/c7/b7ba9547aa700bd20d0420e1794a8jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '麻辣烫'
        },
        {
          id: '1000010',
          iconUrl: '//fuss10.elemecdn.com/a/8a/ec21096d528b7cfd23cdd894f01c6jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '地方菜系'
        }
        ,
        {
          id: '1000011',
          iconUrl: '//fuss10.elemecdn.com/7/b6/235761e50d391445f021922b71789jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '披萨意面'
        }
        ,
        {
          id: '1000012',
          iconUrl: '//fuss10.elemecdn.com/7/d6/6f2631288a44ec177204e05cbcb93jpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
          desc: '地方小吃'
        }
      ]
    }
  },
  computed: {
    // pages[[],[],[],[]]
    pages () {
      const pages = []
      this.iconLists.forEach((item, index) => {
        // 8
        const page = Math.floor(index / 10)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import '~styles/ellipsis.styl'
@import '~styles/varibles.styl'
  .icons >>> .swiper-pagination
    bottom 1px
    
  .icons >>> .swiper-pagination-bullet-active
    background-color black
  .icons
    margin-top .1rem
    .icon
      position relative
      overflow hidden
      float left
      width 20%
      height 0
      padding-bottom 25%
      .icon-img
       position absolute
       top 0
       left 0
       right 0
       bottom .35rem
       box-sizing border-box
       .icon-img-content
        display block
        margin 0 auto
        height 80%
      .icon-desc
        position absolute
        left 0
        right 0
        bottom 0
        height .84rem
        line-height .44rem
        text-align center
        color: #666;
        font-size: .32rem
        ellipsis()
</style>
